package fit.conceptmap.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import fit.conceptmap.beans.JsonBean;
import fit.conceptmap.beans.UserBean;
import fit.conceptmap.services.IShareService;

@Controller
@SessionAttributes({"username", "role" })
public class ShareController {
	
	@Autowired IShareService shareService;
	
	@RequestMapping(value = "/listconceptmap/{idConceptMaps}", method = RequestMethod.GET)
	@ResponseBody
	public List<UserBean> goUpdateProfile(@PathVariable(value="idConceptMaps") String idConceptMaps) {
		return shareService.getListMemberByIdConcepMaps(idConceptMaps);
	}
	
	@RequestMapping(value = "/share/{idConceptMaps}/{idmember}", method = RequestMethod.GET)
	@ResponseBody
	public List<UserBean> share(@PathVariable(value="idConceptMaps") String idConceptMaps,
			@PathVariable("idmember") String idmember) {
		shareService.share(idConceptMaps, idmember);
		return shareService.getListMemberByIdConcepMaps(idConceptMaps);
	}
	
	@RequestMapping(value = "/listprojectshare", method = RequestMethod.GET)
	@ResponseBody
	public List<JsonBean> getListShareByIdMember(@ModelAttribute("username") String username) {
		return shareService.getListShareByIdMember(username);
	}
}
